<?php namespace Phpcmf\Controllers;

/**
 * 二次开发时可以修改本文件，不影响升级覆盖
 */

class Dianzan extends \Phpcmf\Home\Module
{

	public function  dianzan_panduan() {
		//get 参数
		if(!$this->uid){
			$id = (int)\Phpcmf\Service::L('input')->get('id'); //帖子id
		
			$dianzan_tongji = \Phpcmf\Service::M()->db->table('1_quan_form_quantie_dianzan')->where('tieid', $id)->countAllResults();
			$data = [
				'code' => 0,
				'data' => $dianzan_tongji,
				'uid'=> 0,

			];
			$this->_json('1', '未登录',$data);									
		} else {
			$id = (int)\Phpcmf\Service::L('input')->get('id'); //帖子id
		
			$dianzan_data = \Phpcmf\Service::M()->db->table('1_quan_form_quantie_dianzan')->where('tieid', $id)->where('uid', $this->uid)->countAllResults();
			$dianzan_tongji = \Phpcmf\Service::M()->db->table('1_quan_form_quantie_dianzan')->where('tieid', $id)->countAllResults();
			if($dianzan_data){
				$data = [
					'code' => 1,
					'data' => $dianzan_tongji,
					'uid'=> $this->uid,
	
				];
	
				$this->_json('1', '已点赞',$data);
			} else {
				$data = [
					'code' => 2,
					'data' => $dianzan_tongji,
					'uid'=> $this->uid,
	
				];

				$this->_json('0', '未点赞',$data);
			}
		}
		
		
	}
	// 头像
	public function  dianzan_touxiang() {
		$id = (int)\Phpcmf\Service::L('input')->get('id'); //帖子id
		
		$shuju_data = \Phpcmf\Service::M()->table('1_quan_form_quantie_dianzan')->where('tieid', $id)->getAll();
		// 循环头像
		$touxiang_data = [];
		if($shuju_data){
			foreach ($shuju_data as $key => $value) {
				//对信 如果户上传头像，那么显示上传头像
				/*$data2 = \Phpcmf\Service::M()->db->table('member_data')->where('id', $value['uid'])->get()->getRowArray();
				if($data2['is_avatar']==1){
					$touxiang = dr_avatar($value['uid']);
				} else if($data2['is_avatar']==0){
					$weixin_touxiang = \Phpcmf\Service::M()->db->table('member_oauth')->where('uid', $value['uid'])->get()->getRowArray();
					if($weixin_touxiang){
						$touxiang = $weixin_touxiang['avatar'];
					} else {
						$touxiang = dr_avatar($value['uid']);
					}
				}*/
				$touxiang_data[] = dx_touxiang($value['uid']); //dr_avatar($shuju_data['uid'])
			}
		}
	
		$this->_json('0', '点赞头像',$touxiang_data);
	}

}
